package com.ty.day7;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2023/11/30 14:19
 */
public class ThreadPoolDemo02 {
    public static void main(String[] args) {
        //创建线程池(固定个数)
        ExecutorService es= Executors.newFixedThreadPool(3);
        Callable mt = new MyThread001();
        Callable mt1 = new MyThread001();
        Callable mt2 = new MyThread001();

        //使用线程池
        es.submit(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println("什么的干活");
                Thread.sleep(100);
            }
            return null;
        });
        es.submit(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println("送水的");
                Thread.sleep(100);
            }
            return null;
        });
        es.submit(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println("什么的干活");
                Thread.sleep(100);
            }
            return null;
        });
        //关闭线程池
        es.shutdown();
    }
}
